using JetBrains.Annotations;
using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Orchard.Localization;
using Orchard.ContentManagement;

using LuDC.CKEditor.Models;

namespace LuDC.CKEditor.Handlers
{
	[UsedImplicitly]
	public class CKEditorSettingsPartHandler : ContentHandler
	{
		public CKEditorSettingsPartHandler(IRepository<CKEditorSettingsPartRecord> repository)
		{
			T = NullLocalizer.Instance;
			Filters.Add(new ActivatingFilter<CKEditorSettingsPart>("Site"));
			Filters.Add(StorageFilter.For(repository));
			Filters.Add(new TemplateFilterForRecord<CKEditorSettingsPartRecord>("CKEditorSettings", "Parts.CKEditor.CKEditorSettings", "ckeditor"));
		}

		public Localizer T { get; set; }

		protected override void GetItemMetadata(GetContentItemMetadataContext context)
		{
			if (context.ContentItem.ContentType != "Site")
				return;
			context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("CKEditor")));
		}

	}
}
